package com.cencat.product.dto;

import com.cencat.product.entity.Product;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.*;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 产品查询DTO
 * 
 * @author cencat
 * @since 2024-01-01
 */
@Data
@Schema(description = "产品查询DTO")
public class ProductQueryDTO {

    /**
     * 产品ID
     */
    @Min(value = 1, message = "产品ID必须大于0")
    @Schema(description = "产品ID", example = "1")
    private Long id;

    /**
     * 产品ID列表
     */
    @Schema(description = "产品ID列表")
    private List<Long> ids;

    /**
     * 产品编码
     */
    @Size(max = 50, message = "产品编码长度不能超过50个字符")
    @Schema(description = "产品编码", example = "PRD_001")
    private String productCode;

    /**
     * 产品编码列表
     */
    @Schema(description = "产品编码列表")
    private List<String> productCodes;

    /**
     * 产品名称
     */
    @Size(max = 200, message = "产品名称长度不能超过200个字符")
    @Schema(description = "产品名称", example = "iPhone")
    private String productName;

    /**
     * 产品简称
     */
    @Size(max = 100, message = "产品简称长度不能超过100个字符")
    @Schema(description = "产品简称")
    private String shortName;

    /**
     * 产品分类ID
     */
    @Min(value = 1, message = "产品分类ID必须大于0")
    @Schema(description = "产品分类ID", example = "1")
    private Long categoryId;

    /**
     * 产品分类ID列表
     */
    @Schema(description = "产品分类ID列表")
    private List<Long> categoryIds;

    /**
     * 品牌ID
     */
    @Min(value = 1, message = "品牌ID必须大于0")
    @Schema(description = "品牌ID", example = "1")
    private Long brandId;

    /**
     * 品牌ID列表
     */
    @Schema(description = "品牌ID列表")
    private List<Long> brandIds;

    /**
     * 商家ID
     */
    @Min(value = 1, message = "商家ID必须大于0")
    @Schema(description = "商家ID", example = "1")
    private Long merchantId;

    /**
     * 商家ID列表
     */
    @Schema(description = "商家ID列表")
    private List<Long> merchantIds;

    /**
     * 产品类型
     */
    @Schema(description = "产品类型", example = "PHYSICAL")
    private Product.ProductType productType;

    /**
     * 产品类型列表
     */
    @Schema(description = "产品类型列表")
    private List<Product.ProductType> productTypes;

    /**
     * 产品状态
     */
    @Schema(description = "产品状态", example = "ON_SHELF")
    private Product.ProductStatus status;

    /**
     * 产品状态列表
     */
    @Schema(description = "产品状态列表")
    private List<Product.ProductStatus> statuses;

    /**
     * 审核状态
     */
    @Schema(description = "审核状态", example = "APPROVED")
    private Product.AuditStatus auditStatus;

    /**
     * 审核状态列表
     */
    @Schema(description = "审核状态列表")
    private List<Product.AuditStatus> auditStatuses;

    /**
     * 最小销售价格
     */
    @DecimalMin(value = "0.00", message = "最小销售价格不能小于0")
    @Digits(integer = 8, fraction = 2, message = "最小销售价格格式不正确")
    @Schema(description = "最小销售价格", example = "0.00")
    private BigDecimal minSalePrice;

    /**
     * 最大销售价格
     */
    @DecimalMin(value = "0.00", message = "最大销售价格不能小于0")
    @Digits(integer = 8, fraction = 2, message = "最大销售价格格式不正确")
    @Schema(description = "最大销售价格", example = "99999.99")
    private BigDecimal maxSalePrice;

    /**
     * 最小库存数量
     */
    @Min(value = 0, message = "最小库存数量不能小于0")
    @Schema(description = "最小库存数量", example = "0")
    private Integer minStockQuantity;

    /**
     * 最大库存数量
     */
    @Min(value = 0, message = "最大库存数量不能小于0")
    @Schema(description = "最大库存数量", example = "9999")
    private Integer maxStockQuantity;

    /**
     * 是否库存不足
     */
    @Schema(description = "是否库存不足")
    private Boolean isLowStock;

    /**
     * 是否推荐
     */
    @Schema(description = "是否推荐")
    private Boolean isRecommended;

    /**
     * 是否热销
     */
    @Schema(description = "是否热销")
    private Boolean isHot;

    /**
     * 是否新品
     */
    @Schema(description = "是否新品")
    private Boolean isNew;

    /**
     * 是否特价
     */
    @Schema(description = "是否特价")
    private Boolean isSpecial;

    /**
     * 产品颜色
     */
    @Size(max = 50, message = "产品颜色长度不能超过50个字符")
    @Schema(description = "产品颜色")
    private String color;

    /**
     * 产品材质
     */
    @Size(max = 100, message = "产品材质长度不能超过100个字符")
    @Schema(description = "产品材质")
    private String material;

    /**
     * 产品产地
     */
    @Size(max = 100, message = "产品产地长度不能超过100个字符")
    @Schema(description = "产品产地")
    private String origin;

    /**
     * 产品标签
     */
    @Size(max = 500, message = "产品标签长度不能超过500个字符")
    @Schema(description = "产品标签")
    private String tags;

    /**
     * 产品关键词
     */
    @Size(max = 500, message = "产品关键词长度不能超过500个字符")
    @Schema(description = "产品关键词")
    private String keywords;

    /**
     * 创建开始时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Schema(description = "创建开始时间", example = "2024-01-01 00:00:00")
    private LocalDateTime createTimeStart;

    /**
     * 创建结束时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Schema(description = "创建结束时间", example = "2024-12-31 23:59:59")
    private LocalDateTime createTimeEnd;

    /**
     * 更新开始时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Schema(description = "更新开始时间", example = "2024-01-01 00:00:00")
    private LocalDateTime updateTimeStart;

    /**
     * 更新结束时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Schema(description = "更新结束时间", example = "2024-12-31 23:59:59")
    private LocalDateTime updateTimeEnd;

    /**
     * 上架开始时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Schema(description = "上架开始时间", example = "2024-01-01 00:00:00")
    private LocalDateTime shelfTimeStart;

    /**
     * 上架结束时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Schema(description = "上架结束时间", example = "2024-12-31 23:59:59")
    private LocalDateTime shelfTimeEnd;

    /**
     * 审核开始时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Schema(description = "审核开始时间", example = "2024-01-01 00:00:00")
    private LocalDateTime auditTimeStart;

    /**
     * 审核结束时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Schema(description = "审核结束时间", example = "2024-12-31 23:59:59")
    private LocalDateTime auditTimeEnd;

    /**
     * 审核人ID
     */
    @Min(value = 1, message = "审核人ID必须大于0")
    @Schema(description = "审核人ID")
    private Long auditorId;

    /**
     * 关键词搜索
     */
    @Size(max = 200, message = "关键词搜索长度不能超过200个字符")
    @Schema(description = "关键词搜索（搜索产品名称、编码、描述等）")
    private String keyword;

    /**
     * 是否包含已删除数据
     */
    @Schema(description = "是否包含已删除数据", example = "false")
    private Boolean includeDeleted = false;

    /**
     * 租户ID
     */
    @Min(value = 1, message = "租户ID必须大于0")
    @Schema(description = "租户ID")
    private Long tenantId;

    /**
     * 排序字段
     */
    @Size(max = 50, message = "排序字段长度不能超过50个字符")
    @Schema(description = "排序字段", example = "createTime")
    private String sortField = "createTime";

    /**
     * 排序方向
     */
    @Pattern(regexp = "^(ASC|DESC)$", message = "排序方向只能是ASC或DESC")
    @Schema(description = "排序方向", example = "DESC")
    private String sortDirection = "DESC";

    /**
     * 页码
     */
    @Min(value = 1, message = "页码必须大于0")
    @Schema(description = "页码", example = "1")
    private Integer pageNum = 1;

    /**
     * 每页大小
     */
    @Min(value = 1, message = "每页大小必须大于0")
    @Max(value = 1000, message = "每页大小不能超过1000")
    @Schema(description = "每页大小", example = "20")
    private Integer pageSize = 20;

    /**
     * 是否需要分页
     */
    @Schema(description = "是否需要分页", example = "true")
    private Boolean needPaging = true;

    /**
     * 是否需要统计
     */
    @Schema(description = "是否需要统计", example = "false")
    private Boolean needCount = false;

    /**
     * 导出类型
     */
    @Schema(description = "导出类型")
    private ExportType exportType;

    /**
     * 导出字段
     */
    @Schema(description = "导出字段列表")
    private List<String> exportFields;

    /**
     * 导出文件名
     */
    @Size(max = 100, message = "导出文件名长度不能超过100个字符")
    @Schema(description = "导出文件名")
    private String exportFileName;

    /**
     * 是否异步导出
     */
    @Schema(description = "是否异步导出", example = "false")
    private Boolean asyncExport = false;

    /**
     * 导出类型枚举
     */
    public enum ExportType {
        EXCEL("Excel文件"),
        CSV("CSV文件"),
        PDF("PDF文件");

        private final String description;

        ExportType(String description) {
            this.description = description;
        }

        public String getDescription() {
            return description;
        }
    }

    /**
     * 统计类型枚举
     */
    public enum StatType {
        COUNT("数量统计"),
        SALES("销售统计"),
        STOCK("库存统计"),
        PRICE("价格统计");

        private final String description;

        StatType(String description) {
            this.description = description;
        }

        public String getDescription() {
            return description;
        }
    }

    /**
     * 统计维度枚举
     */
    public enum StatDimension {
        CATEGORY("按分类统计"),
        BRAND("按品牌统计"),
        MERCHANT("按商家统计"),
        STATUS("按状态统计"),
        TYPE("按类型统计"),
        DATE("按日期统计");

        private final String description;

        StatDimension(String description) {
            this.description = description;
        }

        public String getDescription() {
            return description;
        }
    }
}